<script src="webpages/forum/portal/js/jquery.js"></script>
<script src="webpages/forum/portal/js/jquery.cookie.js"></script>
<script src="webpages/forum/portal/js/bootstrap.js"></script>
<script src="webpages/forum/portal/js/main.js"></script>
<script>
	//自动加载
	if ($("body").data("autopager") == true) {
		var type = $("body").data("autopager-type");
		var key = $("body").data("autopager-key");
// 		console.log("type="+type);
		var page = 1, totalheight = 0, isDone = false, isRequest = false, 
		loadData = function() {
				++page;
				isRequest = true;
				var url = "article.action?loadListByType&page="+page+"&type="+type+"&keyword="+key;
				$.getJSON(url, function(data) {
					if (data.rows.length>0) {
						page_count = data.total;
						var push = '';
						for ( var i in data.rows) {
							push += template(data.rows[i]);
						}
						$("#post-append").append(push);
					} else {
						console.log('加载完了');
						$("#more").hide();
						isDone = true;
					}
					isRequest = false;
				});
			}, 
		template = function(json) {
				var html = '<div class="media media-yckit">';
				if (json.icon != undefined) {
					html += '<a class="media-left pull-left pr" href="article.action?loadArticleContent&articleId='+json.id+'">';
					html += '<img src="'+json.icon+'" alt="' + json.title + '" width="180">';
					html += '<span class="pa">' + json.categoryName + '</span>';
					html += '</a>';
				}
				html += '<div class="media-body">';
				html += '<h4 class="media-heading"><a href="article.action?loadArticleContent&articleId='+json.id+'">'
						+ json.title + '</a></h4>';
				html += '<div class="media-content">' + json.content + '</div>';
				html += '</div>';
				html += '<div class="clearfix"></div>';
				html += '</div>';
				return html;
		}, page_count = 1;
		// 滚轮翻页（仅前3页）
		$(window).scroll(
			function() {
				if (isDone)
					return false;
				if (isRequest)
					return false;
				if (page > 3)
					return false;
				totalheight = parseFloat($(this).height())
						+ parseFloat($(this).scrollTop());
				if ($(document).height() - totalheight <= 100) {
					loadData();
					if (page == 3) $("#more").show();
			}
		});
		
		$("#more").on("click", function(e) {
			e.preventDefault();
			loadData();
		});
	}
</script>